package com.tydic.springboot.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;

import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * controller层统一异常处理
 *
 * @author niugang
 */
@Aspect
@Component
public class ExceptionControllerAscept {
    private Logger logger = LoggerFactory.getLogger(ExceptionControllerAscept.class);

    /**
     * 匿名切点的方式
     *
     * @param ex
     * @throws ServletException
     * @throws IOException
     */
    @AfterThrowing(value = "execution(public * com.tydic.springboot.controller..*.*(..))", throwing = "ex")
    public Map<String, Object> aroundAdvice(Exception ex) throws ServletException, IOException {
        Map<String, Object> result = new HashMap<>();
        result.put("success", false);
        return result;
    }
}
